package org.vectrics.common.html;

import org.apache.ecs.html.TD;
import org.apache.ecs.html.TR;
import org.apache.log4j.Category;
 
/**
    This class produces an HTML table element with a border between each cell.

    @version $Id: BorderTableOld.java,v 1.1 2006/06/08 12:43:53 vectrics Exp $
    @author <a href="mailto:support@vectrics.com">Mike Moore</a>
*/
public class BorderTableOld extends Table {
    private static Category log = Category.getInstance(BorderTableOld.class);
    private Table innerTable = null;
    private TD bgCell = new TD();
    private String bgColor = "#ffffff";
    private int rowCount = 0;
    private String defaultHeaderCellClass = null;
    private String defaultRowClass1 = "tblRow1";
    private String defaultRowClass2 = "tblRow2";
    private boolean hasHeaderRow = true;
    
    public BorderTableOld() {
        super();
        log.debug("BorderTable() - constructor called.");
        defaultHeaderCellClass = null;
        setCellPadding(0);
        setCellSpacing(0);
        TR row = new TR();
        this.addElement(row);
        bgCell = new TD();
        row.addElement(bgCell);
        bgCell.setBgColor("#999999");
        
        innerTable = new Table();
        innerTable.setCellPadding(0);
        innerTable.setCellSpacing(1);
        innerTable.setWidth("100%");
        bgCell.addElement(innerTable);
    }

    
    public void setDefaultHeaderCellClass(String className) {
        this.defaultHeaderCellClass = className;
    }

    public String getDefaultHeaderCellClass() {
        return(this.defaultHeaderCellClass);
    }
    
    /**
        Set the size of the visible border.
        @param size the size in pixels of the border.
    */
    public void setBorderSize(int size) {
        innerTable.setCellSpacing(size);
    }

    
    public void setBorderColor(String color) {
        bgCell.setBgColor(color);
    }

    
    public org.apache.ecs.html.Table setBgColor(String color) {
        bgColor = color;
        return(this);
    }

    /**
     * Same as adding a TR element to a HTML TABLE.
     */
    public Row addRow() {
        log.debug("addRow() - called.");
        rowCount++;    
        BorderRow row = new BorderRow();
        if (rowCount == 1) {
            if (getDefaultHeaderCellClass() != null) {
                log.debug("addRow() - default header class passed to first row.");
                row.setDefaultCellClass(getDefaultHeaderCellClass());
            }
        }

        /*  */
        if (rowCount % 2 == 0) {
        	if (this.defaultRowClass1 != null)
        		row.setDefaultCellClass(this.defaultRowClass1);
        } else {
        	if (this.defaultRowClass2 != null)
        		row.setDefaultCellClass(this.defaultRowClass2);
        }
        
        
        innerTable.addElement(row);
        return(row);        
    }

}